
<?php
session_start();
require_once '../models/Users.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>Manage Menu</title>
<?php include '../admin/_meta.php';
require_once '../models/_check_admin.php';
$msg="";
if(isset($_POST['btn_submit'])){
	$menuName=$_POST["menuName"];
	$link=$_POST["link"];
	$newPageMenu=$_POST["newPageMenu"];
	$isParent=$_POST["isParent"];
	$parentID=$_POST["parentID"];
	$orderby=$_POST["orderby"];
	if(isset($_POST["isPublished"])){
		$isPublished="1";
	}else
	{
	$isPublished="0";
	}

	$_msg="";
		if(preg_match("/^[0-9]$/",$newPageMenu)){$_msg=null;
		}else{$check=false;}
		
		if(preg_match("/^[0-9]$/",$isParent)){$_msg=null;
		}else{$check=false;}
		
		if(preg_match("/^[0-9]$/",$parentID)){$_msg=null;
		}else{$check=false;}
		if(preg_match("/^[0-9]$/",$orderby)){$_msg=null;
		}else{$check=false;}

	if($check=true){
		$re=Users::addMenuAdmin($menuName,$link,$newPageMenu,$isParent,$parentID,$orderby,$isPublished);
		if($re){
				echo "<script>alert('Thêm thành công!');window.location='ql_menuAdmin.php'</script>";
			}else $_msg.="Lỗi";
	}else{
		$_msg.='<b><span class="error"><br>Nhập sai định dạng.</span></b>';
	}

}
?>
</head>
<body>
<form method="post" action="">
	<div id="firstLine">
		<div id="top-bar">
		<?php include '_top_bar_admin.php';?>
		</div>
	</div>
	<div id="container">
		<div id="header">
			<?php include '_menu_admin.php';?>
		</div>
		<div id="center">
			<div id="table-user">
					<table id="table-admin">
						<tr>
						<td>Name</td>
						<td><input type="text" name="menuName" value="<?php if(isset($_POST["btn_submit"])) echo $menuName;?>" /></td>
					</tr>
					<tr >
						<td>Link</td>
						<td><input type="text" name="link" value="<?php if(isset($_POST["btn_submit"])) echo $link;?>" /></td>
					</tr>
					<tr >
						<td>New Page</td>
						<td><input type="text" name="newPageMenu" value="<?php if(isset($_POST["btn_submit"])) echo $newPageMenu;?>" /></td>
					</tr>
					<tr >
						<td>isParent</td>
						<td><input type="text" name="isParent" value="<?php if(isset($_POST["btn_submit"])) echo $isParent;?>" /></td>
					</tr>
					<tr >
						<td>Parent ID</td>
						<td><input type="text" name="parentID" value="<?php if(isset($_POST["btn_submit"])) echo $parentID;?>" /></td>
					</tr>
					<tr >
						<td>Order</td>
						<td><input type="text" name="orderby" value="<?php if(isset($_POST["btn_submit"])) echo $orderby;?>" /></td>
					</tr>
					<tr >
						<td>isPublished</td>
						<td><input type="checkbox" name="isPublished" /></td>
					</tr>
					<tr>
						<td><input type="submit" name="btn_submit" value="Add" class="btn_submit"></td>
						<td><input type="reset" name="button" value="Reset" class="btn_submit"></td>
					</tr>
					<tr>
						<td colspan="2"><?php if(isset($_POST['btn_submit'])) echo $_msg; ?></td>
					</tr>
					</table>
				<?php Users::listMenuAdmin();?>
			</div>
			</div>
		</div>
	</div>
	</div>
	<div>
		<?php include '_footer_admin.php';?>
	</div>

</body>
</html>